package yf.platform.biz;

import java.io.File;
import java.util.Map;

import net.sf.json.JSONArray;

import org.yfsoft.comm.util.StringUtil;

import yf.platform.bo.BizResult;
import yf.platform.util.ZipUtil;


public class SearchService extends Service {
	
	public BizResult demo(Map<String,String> input) throws Throwable{
		return rst.setCode(0)
				.setType(BizResult.REDIRECT)
				.setPage("WIDGETS/CHART/demo.jsp");
	}
	
	public BizResult searchArchives(Map<String,String> input) throws Throwable{
		String code = input.get("code");
		String root = rst.getAppAttribute("ROOT");
		String archivesRoot = root+"Archives"+File.separator;
		String zippath = StringUtil.format("{0}{1}.zip", archivesRoot,code);
		File zip = new File(zippath);
		if(!zip.exists()){
			return rst.setCode(-1).setMsg("未找到档案!")
					.setType(BizResult.ECHO);
		}
		
		ZipUtil.unzip(archivesRoot+code,zippath);
		String[] filenames = ZipUtil.listFile(archivesRoot+code);
		
		JSONArray list = new JSONArray();
		for(String filename:filenames){
			list.add(code+"/"+filename);
		}
		return rst.setCode(0).setData(list.toString())
				.setType(BizResult.ECHO);
	}
	

}
